feat: add rename with substitute command#3338
Conversation
v3ceban
left a comment
There was a problem hiding this comment.
I considered adding something like this in my initial implementation of bulk ops, but ended up not to due to complexities of renaming directories, nested structures, and converting files <-> dirs. If this only targets files I imagine it should be good.
It's missing the mappings to actually try it out, but the logic looks good to me. There are no regressions with existing bulk ops.
I'll leave organization questions for the core maintener to decide on.
| local start_line = vim.fn.line(opts.use_native == true and "'<" or "v") | ||
| local end_line = vim.fn.line(opts.use_native == true and "'>" or ".") |
alex-courtis
left a comment
There was a problem hiding this comment.
This is looking very promising.
I'm not quite sure how to test this. Do I add something like this to API impl? Not sure what the other arguments should be...
api.fs.rename_bulk = _v(function(n) require("nvim-tree.actions.fs.rename-file").bulk_rename(n) end)Please:
- move the autocommand to rename-file.lua
- add API, doc and keymap
| }) | ||
| end | ||
|
|
||
| vim.api.nvim_create_autocmd("CmdlineLeave", { |
There was a problem hiding this comment.
Firstly, I apologise for the state of autocommands. Having them all in one place is not desirable, and was done purely for startup performance.
Fortunately, this does not have to be a global - it can be placed in it's correct place - rename-file.lua
It can be created when needed i.e. user invokes bulk_rename and removed once the operation is complete. We could probably automatically clean it up after it is done via the {once} option of :help nvim_create_autocmd(). See help.lua for an example.
| local core = require("nvim-tree.core") | ||
| local explorer = core.get_explorer() | ||
| local utils = require("nvim-tree.utils") |
There was a problem hiding this comment.
rename-file.lua already has these, so we should be able to remove these lines 🤞
Motivation #3328
I found this feature on Oil and at least for me this was/is the main reason I use Oil, the first one was visual operations like copy/delete/cut and so on, but this one was missing, basically allowing :%s/old/new to change nodes names renaming and writing to disk.
Changes
1 - Added
M.bulk_renameintorename-file.lua2 - Added
optsintoM.renameto prevent notifications as it is used on a loop3 - Added
optstoget_visual_nodesto correctly allow using'<,'>when needed4 - (Not quite sure where to put yet or organize), Added an
autocmdfor watching ex commandsFeatures
1 -
:%s/old/newwill select or visible nodes and a simple prompt to rename (substitute) if yes they are written to disk2 -
:'<,'>s/old/newworks the same way but on the visual selected partConcerns
1 - Where and how should the new ex commands autocmd be devided?
2 - Should the autocmd of ex commands stay? or instead create at dedicated something like
NvimTreeSubsor whatever to put the tree into substitution mode? - first approach is more natural and expectedI am quite sure that there is a lot of work regarding code organization here, will just wait for your suggestions.